package cn.com.czpb.client.module.news.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import cn.com.czpb.client.R;
import cn.com.czpb.client.utils.LogUtils;
import cn.com.czpb.client.utils.SPUtil;

public class PermisionDialog extends Dialog implements View.OnClickListener {

    TextView tv_queding_id;
    TextView tv_cancel_id;

    private Activity activity;
    private View view;
    private SPUtil spu;

    private OnClickKnowListener listener;
    public PermisionDialog(Context context) {
        super(context);
        activity = (Activity) context;

    }


    public PermisionDialog(Context context, int theme) {
        super(context, theme);
        activity = (Activity) context;
        spu = SPUtil.getInstance();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        init();
    }


    private void init() {
        WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        LogUtils.i("width-->" + width);
        view = LayoutInflater.from(activity).inflate(R.layout.dialog_permision, null);
        tv_queding_id =view.findViewById(R.id.tv_queding_id);
        tv_cancel_id =view.findViewById(R.id.tv_cancel_id);
        setContentView(view);

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        lp.width = (int) (0.92*width);
        lp.dimAmount = 0.6f;
        dialogWindow.setAttributes(lp);
        tv_cancel_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                listener.onCancelClick();
            }
        });
        tv_queding_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                listener.onNextClick();
            }
        });


    }

    public void setOnClickKnowListener(OnClickKnowListener listener) {
        this.listener = listener;
    }


    public interface OnClickKnowListener {
        void onCancelClick();
        void onNextClick();
    }
    public void changeName(String str) {

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.changename_cancel:
                dismiss();
                break;
            default:
                break;
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

}